package com.scpii.universal.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.scpii.universal.hibernate.dao.BaseDao;
import com.scpii.universal.hibernate.entity.CommentTab;
import com.scpii.universal.hibernate.intface.BaseInterface;
import com.scpii.universal.util.SpringBeanFactory;

public class CommentTabService implements BaseInterface<CommentTab> {
	private static final Logger log = LoggerFactory
			.getLogger(CommentTabService.class);

//	private BaseDao<CommentTab> commentTabDao = SpringBeanFactory.commentTabDao;
	private BaseDao<CommentTab> commentTabDao;

	public CommentTab get(Integer id) throws Exception {
		return commentTabDao.get(id);
	}

	public List<CommentTab> getAll() throws Exception {
		return commentTabDao.getAll();
	}

	public CommentTab get(String propertyName, Object value)
			throws Exception {
		return null;
	}

	public List<CommentTab> getList(String propertyName, Object value)
			throws Exception {
		return null;
	}

	public Long getTotalCount() throws Exception {
		return null;
	}

	public void save(CommentTab obj) throws Exception {
		commentTabDao.save(obj);
	}

	public void update(CommentTab obj) throws Exception {

	}

	public void delete(CommentTab obj) throws Exception {

	}

	public void delete(Integer id) throws Exception {

	}

	public List<CommentTab> hqlGetList(String hql,
			Map<String, Object> argsMap) throws Exception {
		return commentTabDao.hqlGetList(hql, argsMap);
	}

	public void hqlUpdate(String namedHqlQuery, Map<String, Object> argsMap)
			throws Exception {
		commentTabDao.hqlUpdate(namedHqlQuery, argsMap);
	}

	public Long hqlGetNums(String namedHqlQuery, Map<String, Object> argsMap)
			throws Exception {
		return commentTabDao.hqlGetNums(namedHqlQuery, argsMap);
	}

	public List<CommentTab> sqlGetList(String sqls,
			Map<String, Object> argsMap) throws Exception {
		return commentTabDao.sqlGetList(sqls, argsMap);
	}

	public void sqlUpdate(String sqls, Map<String, Object> argsMap)
			throws Exception {
		commentTabDao.sqlUpdate(sqls, argsMap);
	}

	public Long sqlGetNum(String sqls, Map<String, Object> argsMap)
			throws Exception {
		return commentTabDao.sqlGetNum(sqls, argsMap);
	}
	
	/**
	 * 根据内容ID，获得针对内容的评论列表
	 * @param contentId
	 * @return
	 * @throws Exception
	 * @author 甘建新
	 * 2012-7-19上午02:27:48
	 */
	public List<CommentTab> getCommentListByContentId(int contentId)throws Exception{
		if (contentId>0) {
			List<CommentTab> comList = new ArrayList<CommentTab>();
			Map<String, Object> argsMap = new HashMap<String, Object>();
			argsMap.put("contentId", contentId);
			comList = this.hqlGetList("GET_COMMENTLIST_BYID", argsMap);
			return comList;
		}
		return null;
	}
	
	public static void main(String[] args) {
		CommentTabService commentTabService = new CommentTabService();
		try {
			List<CommentTab> comList = commentTabService.getCommentListByContentId(1);
			for (CommentTab commentTab : comList) {
				System.out.println(commentTab.getVarCommentName()+commentTab.getIntCommentId());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	
	//Setter

	public void setCommentTabDao(BaseDao<CommentTab> commentTabDao) {
		this.commentTabDao = commentTabDao;
	}
}